import 'package:bruno/bruno.dart';
import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:kq_flutter_core_widget/utils/file_preview_util.dart';
import 'package:kq_flutter_core_widget/utils/kq_screen_util.dart';
import 'package:get/get.dart';
import 'package:kq_flutter_core_widget/widgets/image/kq_image.dart';
import 'package:kq_flutter_core_widget/widgets/imageBox/kq_image_box.dart';
import 'package:kq_flutter_tv_widgets/resources/kq_theme_colors.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

import '../../../router/route_map.dart';
import 'controller.dart';

/// 首页
class HomePage extends StatelessWidget {
  const HomePage({super.key});

  /// 菜单布局
  Widget gridMenuItem(String menuName, GestureTapCallback? onTap) {
    return BrnShadowCard(
      circular: 20.r,
      child: InkWell(
        onTap: onTap,
        child: Container(
          color: KqThemeColors.bgWhite,
          padding: EdgeInsets.all(10.r),
          child: Text(
            menuName,
            style: TextStyle(
              fontWeight: FontWeight.bold,
              color: Colors.black,
              fontSize: 20.sp,
            ),
          ),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    final controller = Get.put(HomeController());
    final state = Get.find<HomeController>().state;

    return Scaffold(
      key: state.scaffoldKey,
      body: GetBuilder<HomeController>(
        builder: (controller) => EasyRefresh(
          controller: controller.refreshController,
          onRefresh: controller.onRefresh,
          onLoad: controller.onLoad,
          child: GridView.count(
            crossAxisCount: 4,
            scrollDirection: Axis.vertical,
            //宽高比
            childAspectRatio: 3 / 1.2,
            padding: EdgeInsets.all(12.r),
            mainAxisSpacing: 12.r,
            crossAxisSpacing: 12.r,
            children: [
              gridMenuItem('按钮组件', () {
                RouteMap.pushButtonDemo();
                // FilePreviewUtil.previewImg([
                //   ImageUrl(
                //       imageType: ImageType.http,
                //       url:
                //       'https://t7.baidu.com/it/u=4162611394,4275913936&fm=193&f=GIF'),
                //   ImageUrl(
                //       imageType: ImageType.http,
                //       url:
                //       'https://img2.baidu.com/it/u=2937346062,2864430088&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=333'),
                //   ImageUrl(
                //       imageType: ImageType.http,
                //       url:
                //       'https://img0.baidu.com/it/u=3109574663,3521128999&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500'),
                // ], position: 1);
              }),
              gridMenuItem('表单组件', () {
                RouteMap.pushFormDemo();
              }),
              gridMenuItem('对话框组件', () {
                RouteMap.pushDialogDemo();
              }),
              gridMenuItem('折叠组件', () {
                RouteMap.pushExpandListDemo();
              }),
              gridMenuItem('网格列表组件', () {
                RouteMap.pushWrapFlowDemo();
              }),
              gridMenuItem('下拉菜单', () {
                RouteMap.pushPullDownDemo();
              }),
              gridMenuItem('表格', () {
                RouteMap.pushTableDemo();
              }),
              gridMenuItem('手写签名', () {
                RouteMap.pushSignaturePadDemo();
              }),
              gridMenuItem('日历', () {
                RouteMap.pushCalendarPageDemo();
              }),
              gridMenuItem('图表', () {
                RouteMap.pushChartPage();
              }),
              gridMenuItem('面包屑', () {
                RouteMap.pushBreadCrumbsDemo();
              }),
              gridMenuItem('气泡', () {
                RouteMap.pushTipsDemoPage();
              }),
              gridMenuItem('选择控件', () {
                RouteMap.pushKqSelectableGridViewDemo();
              }),
              gridMenuItem('侧滑抽屉', () {
                RouteMap.pushDrawerPage();
              }),
              gridMenuItem('卡片', () {
                RouteMap.pushCardPage();
              }),
              gridMenuItem('动画导航框架', () {
                RouteMap.pushTerminalNavDemo();
              }),
              gridMenuItem('popupWindow', () {
                RouteMap.pushPopupWindowDemo();
              }),
              gridMenuItem('更多自定义控件演示', () {
                RouteMap.pushCustomViewsPage();
              }),
              gridMenuItem('更多自定义控件演示2', () {
                RouteMap.pushCustomExpandPage();
              }),
              gridMenuItem('GetNotRoute \n 当要兼容小诸葛原页面时传参等mvc需求时，这可能会很有用', () {
                RouteMap.pushGetNotRouteDemo();
              }),
            ],
          ),
        ),
      ),
    );
  }
}
